from functools import wraps
from time import time

from app.config.logging import logger


def timeit(func):
    """
    方法执行耗时装饰器
    :param func: 原函数
    :return: 原函数结果
    """

    @wraps(func)
    def wrapper(*args, **kwargs):
        start_time = time()
        result = func(*args, **kwargs)
        logger.info(f"func:{func.__name__} elapsed time:{round(time() - start_time, 2)}")
        return result

    return wrapper
